package org.grayrabbit.cloud.core.application;

import org.grayrabbit.cloud.core.biz.BizUtility;
import org.grayrabbit.cloud.core.config.ConfiguratorException;
import org.grayrabbit.cloud.core.config.SimpleXmlConfigurator;
import org.grayrabbit.cloud.core.module.Module;
import org.grayrabbit.cloud.core.rpc.Argument;
import org.grayrabbit.cloud.core.rpc.Result;


/**
 * @author sys53
 * @version 1.0
 * @created 2011-6-12 15:58:51
 */
public class BizApplication extends Application<Result,Module<Result,Argument>> {
	private boolean server = false;
	public BizApplication(String url,boolean server) {
		super(new SimpleXmlConfigurator(url));
		BizUtility.initialize(this,server);
		this.server = server;
	}

	/**
	 * 
	 * @param paramString
	 */
	protected String getModuleClass(String name) {
		return getProperty("module", name, "module");
	}

	public String[] getModules() {
		String names = getProperty("application", null, "modules");
		String[] result = names.split(",");
		for (int i = 0; i < result.length; i++)
		result[i] = result[i].trim();
		return result;
	}

	/**
	 * 
	 * @param paramString
	 */
	public String getModuleType(String name) {
		return getProperty("module", name, "type");
	}

	private String getProperty(String category, String name, String property) {
		try {
			return BizUtility.getProperty(category, name, property,server);
		} catch (ConfiguratorException e) {
			throw new RuntimeException(e);
		}
		
	}
}